using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace QLVMB
{
    public partial class frmChuyenBayHomNay : Form
    {
        public frmChuyenBayHomNay()
        {
            InitializeComponent();
        }

        public void XuatDuLieu(DataGridView dtg, List<DTO.ChuyenBay> cb , List<DTO.ChiTietChuyenBay> ctcb  , List<DTO.SanBay> sb, int i)
        {
            //int m = dtg.Rows.Count;
            string[] l = new string[8];
            int b = 0;
            l[b++] = cb[i].MaChuyenBay;
            string s = cb[i].NgayBay.Day + "/" + cb[i].NgayBay.Month + "/" + cb[i].NgayBay.Year;
            l[b++] = s;
            string d = cb[i].ThoiGian.Hour + ":" + cb[i].ThoiGian.Minute;
            l[b++] = d;
            for (int j = 0; j < sb.Count; j++)
            {
                if (cb[i].MaSanBayDi == sb[j].MaSanBay)
                    l[b++] = sb[j].TenSanBay;
            }
            for (int j = 0; j < sb.Count; j++)
            {
                if (cb[i].MaSanBayDen == sb[j].MaSanBay)
                    l[b++] = sb[j].TenSanBay;
            }
            int flag1 = 0;
            for (int k = 0; k < ctcb.Count; k++)
            {
                if (cb[i].MaChuyenBay == ctcb[k].MaChuyenBay)
                {

                    for (int j = 0; j < sb.Count; j++)
                    {
                        if (ctcb[k].SanBayTrungGian == sb[j].MaSanBay)
                        {
                            flag1 = 1;
                            l[b++] = sb[j].TenSanBay;
                        }
                    }
                   
                }

            }
            if (flag1 == 0)
                l[b++] = "Null";
            l[b++] = cb[i].SoGheThuongGia.ToString();
            l[b++] = cb[i].SoGhePhoThong.ToString();
            //l.Length = i;
 
            dtg.Rows.Add(l);

        }
               

        //private void button1_Click(object sender, EventArgs e)
        //{
        //    frmChuyenBayHomNay_Load(sender, e);
        //}

        private void btQuaylai_Click(object sender, EventArgs e)
        {
            Form a = new frmMainKH();        
            a.Show();
        }

        private void frmChuyenBayHomNay_Load(object sender, EventArgs e)
        {
            dataGridView1.Rows.Clear();
            List<DTO.ChuyenBay> cb = new List<DTO.ChuyenBay>();
            List<DTO.ChiTietChuyenBay> ctcb = new List<DTO.ChiTietChuyenBay>();
            List<DTO.SanBay> sb = new List<DTO.SanBay>();
            int flag = 0;
            if (BUS.ChuyenBayBUS.ChonHetChuyenBay(cb) == BUS.ChuyenBayBUSResult.OK && BUS.SanBayBUS.ChonHet(sb) == BUS.SanBayBUSResult.OK && BUS.ChiTietChuyenBayBUS.ChonHetCTChuyenBay(ctcb) == BUS.ChiTietChuyenBayBUSResult.OK)
            {
                for (int i = 0; i < cb.Count; i++)
                {
                    DateTime a = DateTime.Parse(dateTimePicker1.Value.ToString());
                    if (a.Day == cb[i].NgayBay.Day && a.Month == cb[i].NgayBay.Month && a.Year == cb[i].NgayBay.Year)
                    {
                        flag = 1;
                        //dataGridView1.Rows.Insert(dataGridView1.Rows.Count - 1);
                        XuatDuLieu(dataGridView1, cb, ctcb, sb, i);
                    }

                }
                if (flag == 0)
                {
                    MessageBox.Show("Khong tim thay");
                }
            }
        }

        private void btTra_Click(object sender, EventArgs e)
        {
            frmChuyenBayHomNay_Load(sender, e);
        }

        
    

    }

}